<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Admin\Controller;

use ApiClient\Order\Interfaces\OrderServiceInterface;
use App\Api\Request\IndexRequest;
use Common\Constants\ResponseCode;
use Common\Kernel\Exception\BusinessException;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;

#[Controller]
class IndexController extends AbstractController
{
    #[Inject]
    protected OrderServiceInterface $orderServiceClient;

    #[GetMapping(path: 'index')]
    public function index()
    {
//        $validated = $request->validated();
//        throw new BusinessException(ResponseCode::ERROR);

        return $this->response->successJson([
            'name' => 'Jesse',
            'method' => $this->request->getMethod(),
            'user' => $this->request->input('user', 'Hyperf Admin'),
        ]);
    }

    /**
     * 测试rpc请求
     *
     * @return array
     */
    public function test(): array
    {
        return $this->orderServiceClient->getList([]);
    }

    /**
     * @return array
     */
    public function testQueue(): array
    {
        return $this->orderServiceClient->testQueue(['name' => 'Jesse']);
    }
}
